package here.controller;

import here.model.Here;
import here.model.Local;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CadastroLocal extends AbstractCommand{

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try{
			Here here = Here.getInstance();
			
			String endereco = request.getParameter("endereco");			
			String nome = request.getParameter("nome");
			
			Local l = new Local();
			l.setEndereco(endereco);
			l.setNome(nome);
			
			here.addLocal(l);
			
			RequestDispatcher view = request.getRequestDispatcher("/home.jsp");
			view.forward(request, response);
			
		}catch (Exception e){
			request.setAttribute("msgErro", e.getMessage());			
			request.getRequestDispatcher("/error2.jsp").forward(request, response);	
		}
		
	}

}
